<?php
if ( !defined('IN_SEC') ){exit();}
?>
<?php include template("admin_header");?>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>
<?php include template("admin_breadcrumb");?>
					</div>

					<div class="page-content">
						<div class="page-header">
							<h1><?php echo $_G['admincp']['actname']; ?><small><i class="icon-double-angle-right"></i><?php echo $_G['admincp']['optname']; ?></small></h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->

								<div class="row-fluid">
									<div class="span12">
										<div class="widget-box">
											<div class="widget-header widget-header-blue widget-header-flat">
												<h4 class="lighter"><?php echo $team['name']; ?></h4>
											</div>

											<div class="widget-body">
												<div class="widget-main">
													<div id="fuelux-wizard" class="row-fluid" data-target="#step-container">
														<ul class="wizard-steps">
															<li data-target="#step1" class="active">
																<span class="step">1</span>
																<span class="title">项目信息</span>
															</li>
															<li data-target="#step2">
																<span class="step">3</span>
																<span class="title">授权验证</span>
															</li>
														</ul>
													</div>

													<hr />
													<div class="step-content row-fluid position-relative" id="step-container">
													<form class="form-horizontal" action="?action=verify&operation=edit&id=<?php echo $team['id']; ?>" id="validation-form" method="post">
                                                    	<input name="id" value="<?php echo $team['id']; ?>" type="hidden" />
														<div class="step-pane active" id="step1">
																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="key">应用密钥:</label>

																	<div class="col-xs-12 col-sm-3">
																		<div class="clearfix input-icon input-icon-right">
																			<input type="text" name="key" id="key" value="<?php echo $team['key']; ?>" class="col-xs-12 col-sm-12" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="secret">加密代码:</label>

																	<div class="col-xs-12 col-sm-3">
																		<div class="clearfix">
																			<input type="text" name="secret" id="secret" value="<?php echo $team['secret']; ?>" autocomplete="off" class="col-xs-12 col-sm-12" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="state">是否启用</label>

																	<div class="col-xs-12 col-sm-9">
                                                                    	<input name="status" value="1" class="ace ace-switch" type="checkbox" <?php echo $team['status'] ? '' : 'checked'; ?>><span class="lbl"></span>
																	</div>
																</div>
														</div>

														<div class="step-pane" id="step2">
																<div class="alert alert-info">
																	<button type="button" class="close" data-dismiss="alert">
																		<i class="icon-remove"></i>
																	</button>
																	<strong>注意!</strong> 您需要输入您的密码来进行授权操作
																</div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right">密码</label>

																	<div class="col-xs-12 col-sm-9">
																			<input type="password" name="confirm_password" value="" class="col-xs-12 col-sm-5" />
																	</div>
																</div>
														</div>
														</form>
													</div>

													<hr />
													<div class="row-fluid wizard-actions">
														<button class="btn btn-prev"><i class="icon-arrow-left"></i>上一步</button>
														<button class="btn btn-success btn-next" data-last="完成">下一步<i class="icon-arrow-right icon-on-right"></i></button>
													</div>
												</div><!-- /widget-main -->
											</div><!-- /widget-body -->
										</div>
									</div>
								</div>
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div>
<?php include template("admin_footer");?>
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="/static/ace/assets/css/jquery-ui-1.10.3.custom.min.css" />
		<link rel="stylesheet" href="/static/ace/assets/css/select2.css" />
		<!-- page specific plugin scripts -->
		<script src="/static/derek/md5.js"></script>

		<script src="/static/ace/assets/js/fuelux/fuelux.wizard.min.js"></script>
		<script src="/static/ace/assets/js/jquery.validate.min.js"></script>
		<script src="/static/ace/assets/js/additional-methods.min.js"></script>
		<script src="/static/ace/assets/js/jquery.maskedinput.min.js"></script>
		<script src="/static/ace/assets/js/select2.min.js"></script>
		<script type="text/javascript">
			D.Main = {
				init : function(){
					$('#key').on('blur', function(){
						if( $(this).val() && !$('#secret').val() ){
							$('#secret').val(hex_md5($(this).val()));
						}
					});
				}
			}
			jQuery(function($) {
				$('[data-rel=tooltip]').tooltip();
			
				$(".select2").css('width','200px').select2({allowClear:true})
				.on('change', function(){
					$(this).closest('form').validate().element($(this));
				}); 

				var $validation = false;
				$('#fuelux-wizard').ace_wizard().on('change' , function(e, info){
					if(info.step == 1 && $validation) {
						if(!$('#validation-form').valid()) return false;
					}
				}).on('finished', function(e) {
					var data = $('#validation-form').serialize();
					var loading = bootbox.dialog({
						message: '<div class="tree-loading" style="text-align: center;"><i class="icon-refresh icon-spin blue"></i></div>' 
					});
					D.ajax.postdata($('#validation-form').attr('action'), data, function(json){
						bootbox.hideAll();
						var buttons = json.error ? {
							danger : {
								label : "错误",
								className : "btn-sm btn-primary"
							}
						} : {
							success : {
								label : "OK",
								className : "btn-sm btn-primary",
								callback : function(){
									window.location.reload();
								}
							}
						};
						bootbox.dialog({
							message: json.data, 
							buttons: buttons
						});
					});
				}).on('stepclick', function(e){
					//return false;//prevent clicking on steps
				});
			
				//documentation : http://docs.jquery.com/Plugins/Validation/validate
			
				$.mask.definitions['~']='[+-]';
				$('#contact_phone').mask('99999999999');

				jQuery.validator.addMethod("phone", function (value, element) {
					return this.optional(element) || /^1[3458][\d]{9}$/.test(value);
				}, "请输入一个有效的手机号码.");
			
				$('#validation-form').validate({
					errorElement: 'div',
					errorClass: 'help-block',
					focusInvalid: false,
					rules: {
						email: {
							required: true,
							email:true
						},
						password: {
							required: true,
							minlength: 5
						},
						password2: {
							required: true,
							minlength: 5,
							equalTo: "#password"
						},
						name: {
							required: true
						},
						phone: {
							required: true,
							phone: 'required'
						},
						url: {
							required: true,
							url: true
						},
						comment: {
							required: true
						},
						state: {
							required: true
						},
						platform: {
							required: true
						},
						subscription: {
							required: true
						},
						gender: 'required',
						agree: 'required'
					},
			
					messages: {
						email: {
							required: "Please provide a valid email.",
							email: "Please provide a valid email."
						},
						password: {
							required: "Please specify a password.",
							minlength: "Please specify a secure password."
						},
						subscription: "Please choose at least one option",
						gender: "Please choose gender",
						agree: "Please accept our policy"
					},
			
					invalidHandler: function (event, validator) { //display error alert on form submit   
						$('.alert-danger', $('.login-form')).show();
					},
			
					highlight: function (e) {
						$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
					},
			
					success: function (e) {
						$(e).closest('.form-group').removeClass('has-error').addClass('has-info');
						$(e).remove();
					},
			
					errorPlacement: function (error, element) {
						if(element.is(':checkbox') || element.is(':radio')) {
							var controls = element.closest('div[class*="col-"]');
							if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
							else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
						}
						else if(element.is('.select2')) {
							error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
						}
						else if(element.is('.chosen-select')) {
							error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
						}
						else error.insertAfter(element.parent());
					},
			
					submitHandler: function (form) {
					},
					invalidHandler: function (form) {
					}
				});
			
				$('#modal-wizard .modal-header').ace_wizard();
				$('#modal-wizard .wizard-actions .btn[data-dismiss=modal]').removeAttr('disabled');

				//show the user info on right or left depending on its position
				$('.memberdiv').on('mouseenter', function(){
					var $this = $(this);
					var $parent = $this.closest('.tab-pane');
			
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $this.offset();
					var w2 = $this.width();
			
					var place = 'left';
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) place = 'right';
					
					$this.find('.popover').removeClass('right left').addClass(place);
				}).on('click', function() {
					if( $(this).find('.avatar').hasClass('btn-success') ){
						$(this).find('.member-checkbox').prop('checked', false);
						$(this).find('.avatar').removeClass('btn-success');
					}else{
						$(this).find('.member-checkbox').prop('checked', true);
						$(this).find('.avatar').addClass('btn-success');
					}
					return false;
				});
				$('.nav-tabs li a:first').click();
			});
		</script>
<style>
.avatar.selected{border:1px solid black; opacity: 0.6;}
</style>
</body>
</html>
